home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / diffs / make-3.71 / job.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-05  |  6.9 KB  |  287 lines

  1. *** orig/make-3.71/job.c    Thu Jul 21 01:30:04 1994
  2. --- src/make-3.71/job.c    Wed Jul 27 16:21:42 1994
  3. ***************
  4. *** 28,33 ****
  5. --- 28,45 ----
  6.   /* Default shell to use.  */
  7.   char default_shell[] = "/bin/sh";
  8.   
  9. + #ifdef __MSDOS__
  10. + #include <process.h>
  11. + static int dos_pid = 123;
  12. + static int dos_status = 0;
  13. + static char *bname = 0;
  14. + static char *bename = 0;
  15. + static int is_batch_file = 0;
  16. + #define PATH_SEPARATOR_CHAR ';'
  17. + #else /* MSDOS */
  18. + #define PATH_SEPARATOR_CHAR ':'
  19. + #endif /* ?MSDOS */
  20.   /* If NGROUPS_MAX == 0 then try other methods for finding a real value.  */
  21.   #if defined (NGROUPS_MAX) && NGROUPS_MAX == 0
  22.   #undef NGROUPS_MAX
  23. ***************
  24. *** 260,265 ****
  25. --- 272,278 ----
  26.       }
  27.         else if (pid == 0)
  28.       {
  29. + #ifndef __MSDOS__
  30.         /* No remote children.  Check for local children.  */
  31.   
  32.         if (any_local)
  33. ***************
  34. *** 308,313 ****
  35. --- 321,333 ----
  36.             exit_sig = WIFSIGNALED (status) ? WTERMSIG (status) : 0;
  37.             coredump = WCOREDUMP (status);
  38.           }
  39. + #else /* MSDOS */
  40. +       pid = dos_pid-1;
  41. +       status = dos_status;
  42. +       exit_code = dos_status;
  43. +       exit_sig = 0;
  44. +       coredump = 0;
  45. + #endif /* ?MSDOS */
  46.       }
  47.         else
  48.       /* We got a remote child.  */
  49. ***************
  50. *** 474,479 ****
  51. --- 494,502 ----
  52.     free ((char *) child);
  53.   }
  54.   
  55. + #ifdef __MSDOS__
  56. + void unblock_sigs(){}
  57. + #else /* MSDOS */
  58.   #ifdef    POSIX
  59.   extern sigset_t fatal_signal_set;
  60.   
  61. ***************
  62. *** 485,490 ****
  63. --- 508,514 ----
  64.     sigprocmask (SIG_SETMASK, &empty, (sigset_t *) 0);
  65.   }
  66.   #endif
  67. + #endif /* ?MSDOS */
  68.   
  69.   /* Start a job to run the commands specified in CHILD.
  70.      CHILD is updated to reflect the commands and ID of the child process.  */
  71. ***************
  72. *** 618,623 ****
  73. --- 642,649 ----
  74.     if (child->environment == 0)
  75.       child->environment = target_environment (child->file);
  76.   
  77. + #ifndef __MSDOS__
  78.     /* start_waiting_job has set CHILD->remote if we can start a remote job.  */
  79.     if (child->remote)
  80.       {
  81. ***************
  82. *** 666,672 ****
  83.         goto error;
  84.       }
  85.       }
  86.     /* We are the parent side.  Set the state to
  87.        say the commands are running and return.  */
  88.   
  89. --- 692,712 ----
  90.         goto error;
  91.       }
  92.       }
  93. ! #else
  94. !   dos_status = spawnvpe(P_WAIT, argv[0], argv, child->environment);
  95. !   dead_children++;
  96. !   child->pid = dos_pid++;
  97. !   if (is_batch_file)
  98. !   {
  99. !     is_batch_file = 0;
  100. !     remove(bname); /* ignore errors */
  101. !     if (access(bename,0))
  102. !       dos_status = 1;
  103. !     else
  104. !       dos_status = 0;
  105. !     remove(bename);
  106. !   }
  107. ! #endif
  108.     /* We are the parent side.  Set the state to
  109.        say the commands are running and return.  */
  110.   
  111. ***************
  112. *** 924,929 ****
  113. --- 964,972 ----
  114.   static int
  115.   load_too_high ()
  116.   {
  117. + #ifdef __MSDOS__
  118. +   return 1;
  119. + #else
  120.     extern int getloadavg ();
  121.     double load;
  122.   
  123. ***************
  124. *** 949,954 ****
  125. --- 992,998 ----
  126.     user_access ();
  127.   
  128.     return load >= max_load_average;
  129. + #endif /* ?__MSDOS__ */
  130.   }
  131.   
  132.   /* Start jobs that are waiting for the load to be lower.  */
  133. ***************
  134. *** 1012,1018 ****
  135. --- 1056,1066 ----
  136.     if (path == 0 || path[0] == '\0')
  137.       path = default_path;
  138.   
  139. + #ifdef __MSDOS__
  140. +   if (strpbrk (file, "/\\:") != 0)
  141. + #else
  142.     if (index (file, '/') != 0)
  143. + #endif
  144.       {
  145.         strcpy (program, file);
  146.         return 1;
  147. ***************
  148. *** 1049,1055 ****
  149.         int perm;
  150.         char *p;
  151.   
  152. !       p = index (path, ':');
  153.         if (p == 0)
  154.           p = path + strlen (path);
  155.   
  156. --- 1097,1103 ----
  157.         int perm;
  158.         char *p;
  159.   
  160. !       p = index (path, PATH_SEPARATOR_CHAR);
  161.         if (p == 0)
  162.           p = path + strlen (path);
  163.   
  164. ***************
  165. *** 1189,1200 ****
  166. --- 1237,1258 ----
  167.        char *line, **restp;
  168.        char *shell, *ifs;
  169.   {
  170. + #ifdef __MSDOS__
  171. +   static char sh_chars[] = "|<>";
  172. +   static char *sh_cmds[] = {
  173. +     "break", "call", "cd", "chcp", "chdir", "cls", "copy", "ctty",
  174. +     "date", "del", "dir", "echo", "erase", "exit", "for"
  175. +     "goto", "if", "if", "md", "mkdir", "path", "pause", "prompt",
  176. +     "rem", "ren", "rename", "set", "shift", "time", "type"
  177. +     "ver", "verify", "vol", ":", 0};
  178. + #else
  179.     static char sh_chars[] = "#;\"*?[]&|<>(){}$`^";
  180.     static char *sh_cmds[] = { "cd", "eval", "exec", "exit", "login",
  181.                    "logout", "set", "umask", "wait", "while", "for",
  182.                    "case", "if", ":", ".", "break", "continue",
  183.                    "export", "read", "readonly", "shift", "times",
  184.                    "trap", "switch", 0 };
  185. + #endif
  186.     register int i;
  187.     register char *p;
  188.     register char *ap;
  189. ***************
  190. *** 1400,1406 ****
  191.         free (new_argv[0]);
  192.         free (new_argv);
  193.       }
  194.     {
  195.       /* SHELL may be a multi-word command.  Construct a command line
  196.          "SHELL -c LINE", with all special chars in LINE escaped.
  197. --- 1458,1525 ----
  198.         free (new_argv[0]);
  199.         free (new_argv);
  200.       }
  201. ! #ifdef __MSDOS__
  202. !   {
  203. !     FILE *batch;
  204. !     char *linep;
  205. !     int pstate=1;
  206. !     is_batch_file = 1;
  207. !     if (!bname)
  208. !     {
  209. !       bname = tempnam(".", "mk");
  210. !       for (i=0; bname[i]; i++)
  211. !         if (bname[i] == '/')
  212. !           bname[i] = '\\';
  213. !       bename = (char *)malloc(strlen(bname)+5);
  214. !       strcpy(bename, bname);
  215. !       strcat(bname, ".bat");
  216. !       strcat(bename, ".err");
  217. !     }
  218. !     batch=fopen(bename, "w"); /* create a file */
  219. !     if (batch) fclose(batch);
  220. !     batch = fopen(bname, "w");
  221. !     fputs("@echo off\n", batch);
  222. !     linep = line;
  223. !     while (1)
  224. !     {
  225. !       if (*linep == 0)
  226. !     break;
  227. !       switch (pstate)
  228. !       {
  229. !       case 1: /* eat whitespace at bol or after special char */
  230. !     if (*linep && *linep <= ' ')
  231. !       linep++;
  232. !     else
  233. !       pstate = 2;
  234. !     break;
  235. !       case 2: /* dosify */
  236. !     if (strchr("><|", *linep))
  237. !       pstate = 3;
  238. !     else if (*linep > ' ')
  239. !     {
  240. !       if (*linep == '/')
  241. !         fputc('\\', batch);
  242. !       else
  243. !         fputc(*linep, batch);
  244. !       linep++;
  245. !     }
  246. !     else
  247. !       pstate = 3;
  248. !     break;
  249. !       case 3: /* pass */
  250. !     if (strchr("><|", *linep))
  251. !       pstate = 1;
  252. !     fputc(*linep++, batch);
  253. !     break;
  254. !       }
  255. !     }
  256. !     fprintf(batch, "\nif errorlevel 1 del %s\n", bename);
  257. !     fclose(batch);
  258. !     new_argv = (char **)xmalloc(2 * sizeof(char *));
  259. !     new_argv[0] = strdup(bname);
  260. !     new_argv[1] = 0;
  261. !   }
  262. ! #else /* __MSDOS__ */
  263.     {
  264.       /* SHELL may be a multi-word command.  Construct a command line
  265.          "SHELL -c LINE", with all special chars in LINE escaped.
  266. ***************
  267. *** 1458,1464 ****
  268.       new_argv = construct_command_argv_internal (new_line, (char **) NULL,
  269.                           (char *) 0, (char *) 0);
  270.     }
  271.     return new_argv;
  272.   }
  273.   
  274. --- 1577,1583 ----
  275.       new_argv = construct_command_argv_internal (new_line, (char **) NULL,
  276.                           (char *) 0, (char *) 0);
  277.     }
  278. ! #endif /* ?__MSDOS__ */
  279.     return new_argv;
  280.   }
  281.   
  282.